package com.example.ele_guarantee_hh_pro.trigger;
import com.cloudcc.deveditor.core.SendEmail;
import com.cloudcc.deveditor.trigger.TriggerEditor;
import com.cloudcc.deveditor.core.CCObject;
import com.example.ele_guarantee_hh_pro.comclass.SaveAccountTest;
import com.sun.org.apache.bcel.internal.generic.IF_ACMPEQ;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/*事件*/
public class event extends TriggerEditor{

    /*商机升迁，发送通知 */
    public void afterInsert() {

        Date date = new Date();
        SimpleDateFormat sf2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String now = sf2.format(date);
        /*商机升迁，发送通知*/
        String eleoppTYPE = "202385551266A597FF1B";
        String ghztType = "已失效";
        String eleoppJieduanType = "1-发现机会";
        String eleoppJieduanType2 = "2-初次拜访";
        String jieduan3 = "3-客情调研";
        String start_status = "已生效";
        String frequece = "";
        String frequeceType = "低频";
        String recordType = record_new.get("recordtype") == null ? "" : record_new.get("recordtype") + "";
        String sctp1 = record_new.get("sctp") == null ? "" : record_new.get("sctp") + "";
//

        String position = record_new.get("position") == null ? "" : record_new.get("position") + "";
        /*客户Id*/
        String relateid = record_new.get("relateid") == null ? "" : record_new.get("relateid") + "";
        String obj_suffix = "";
        if (!"".equals(relateid)) {
            obj_suffix = relateid.substring(0, 3);
        }
        String sql2 = "select SCHEMETABLE_NAME api from tp_sys_object where prefix='" + obj_suffix + "'";
        List<CCObject> list2 = this.cqlQuery("works", sql2);
        String api = "";
        String findAccount = "";
        String userInfoUserId = userInfo.getUserId();
        if (list2.size() > 0) {
            api = list2.get(0).get("api") == null ? "" : list2.get(0).get("api") + "";
        }
        if (api.equals("account") || api.equals("Account")) {
            findAccount = "select * from eleopp where khmc ='" + relateid + "' and is_deleted ='0' and ownerid = '" + userInfoUserId + "' ";
        } else if (api.equals("eleopp")) {
            findAccount = "select * from eleopp where id ='" + relateid + "' ";
        }
        List<CCObject> accountInfoList = this.cqlQuery("eleopp", findAccount);

        if (accountInfoList.size() > 0) {

            for (int i = 0; i <accountInfoList.size() ; i++) {
                int num;
                num = i;


                String jieduan = accountInfoList.get(i).get("jieduan") == null ? "" : accountInfoList.get(i).get("jieduan") + "";
                String es_time = accountInfoList.get(i).get("es_time") == null ? "" : accountInfoList.get(i).get("es_time") + "";
                String intention = accountInfoList.get(i).get("intention") == null ? "" : accountInfoList.get(i).get("intention") + "";
                String fk_psmc = accountInfoList.get(i).get("fk_psmc") == null ? "" : accountInfoList.get(i).get("fk_psmc") + "";
                String eleoppName = accountInfoList.get(i).get("name") == null ? "" : accountInfoList.get(i).get("name") + "";
                String id = accountInfoList.get(i).get("id") == null ? "" : accountInfoList.get(i).get("id") + "";
                String ownerid = accountInfoList.get(i).get("ownerid") == null ? "" : accountInfoList.get(i).get("ownerid") + "";


                //阶段
                //关联客户
                String khmc = accountInfoList.get(i).get("khmc") == null ? "" : accountInfoList.get(i).get("khmc") + "";
                //审批状态
                String spzt = accountInfoList.get(i).get("spzt") == null ? "" : accountInfoList.get(i).get("spzt") + "";
                //商机名称
                String name = accountInfoList.get(i).get("name") == null ? "" : accountInfoList.get(i).get("name") + "";
                //近一年公招项目投标次数
                String one_year_num = accountInfoList.get(i).get("one_year_num") == null ? "" : accountInfoList.get(i).get("one_year_num") + "";
                //投标习惯
                String habbit = accountInfoList.get(i).get("habbit") == null ? "" : accountInfoList.get(i).get("habbit") + "";
                //投标策略
                String strategy = accountInfoList.get(i).get("strategy") == null ? "" : accountInfoList.get(i).get("strategy") + "";
                //保证金缴纳方式
                String pay_method = accountInfoList.get(i).get("pay_method") == null ? "" : accountInfoList.get(i).get("pay_method") + "";
                //投标决策人
                String decision = accountInfoList.get(i).get("decision") == null ? "" : accountInfoList.get(i).get("decision") + "";
                //投标经办人
                String tender = accountInfoList.get(i).get("tender") == null ? "" : accountInfoList.get(i).get("tender") + "";

                /*审批机构负责人*/
                String leader = accountInfoList.get(i).get("leader") == null ? "" : accountInfoList.get(i).get("leader") + "";

                String sqyy = accountInfoList.get(i).get("sqyy") == null ? "" : accountInfoList.get(i).get("sqyy") + "";


                String findeleNumSql = "select frequece from  ele_num where id ='" + fk_psmc + "' ";
                List<CCObject> ccObjects = this.cqlQuery("ele_num", findeleNumSql);
                if (ccObjects.size() > 0) {
                    frequece = ccObjects.get(0).get("frequece") == null ? "" : ccObjects.get(0).get("frequece") + "";
                }
                /*中高频*/
                if ((jieduan.equals(eleoppJieduanType)) && (!frequece.equals(frequeceType))) {
                    if (sctp1.equals("") && position.equals("")) {
                        // if (true) trigger.addErrorMessage("上传图片或者地址必填其一");
                    }
                    String sctp = record_new.get("sctp") == null ? "" : record_new.get("sctp") + "";
                    if (!sctp.equals("")) {
                        String updateEleoppJIEduan = "update eleopp set jieduan ='" + eleoppJieduanType2 + "',recordtype='" + eleoppTYPE + "',es_time='" + now + "',timeEndOne='" + now + "',timeTwoStart='" + now + "' where id ='" + id + "' ";
                        this.cqlQuery("eleopp", updateEleoppJIEduan);
                        //阶段2，升迁三阶段，所有字段填写完毕；更新管护小组状态为第三阶段
                        if (
                                org.apache.commons.lang3.StringUtils.isNotBlank(one_year_num) &&
                                        org.apache.commons.lang3.StringUtils.isNotBlank(habbit) &&
                                        org.apache.commons.lang3.StringUtils.isNotBlank(strategy) &&
                                        org.apache.commons.lang3.StringUtils.isNotBlank(pay_method) &&
                                        org.apache.commons.lang3.StringUtils.isNotBlank(decision) &&
                                        org.apache.commons.lang3.StringUtils.isNotBlank(tender)) {

                            String manager_sql = "update manage_group set ghzt='" + start_status + "',get_time='" + now + "'" +
                                    "where fk_account='" + khmc + "' " +
                                    "and is_deleted='0' " +
                                    "and fk_ccuser='" + ownerid + "'";
                            String eleopp3_sql = "update eleopp set jieduan='" + jieduan3 + "',timeTwoEnd='" + now + "',timeThreeStart='" + now + "' " +
                                    "where id='" + id + "'";

                            //更新三阶段
                            this.cqlQuery("eleopp", eleopp3_sql);
                            //更新管护小组状态
                            this.cqlQuery("manage_group", manager_sql);

                        }
                    } else if(!position.equals("")) {
                        final double EARTH_RADIUS = 6378137;
                        SaveAccountTest saveAccountTest = new SaveAccountTest(userInfo);
                        String gen = saveAccountTest.gen(position);
                        net.sf.json.JSONObject genInfo = net.sf.json.JSONObject.fromObject(gen);
                        net.sf.json.JSONArray geocodes = genInfo.getJSONArray("geocodes");
                        String location = geocodes.getJSONObject(0).getString("location");
                        String[] split = location.split(",");

                        /*经度*/
                        String lat = split[0];
                        String yg_lat = "";

                        /*维度*/
                        String lon = split[1];
                        String yg_lon = "";

                        String findKeHu = "select id,name,dlwzco,dlwzla from manage_group where fk_account = '" + khmc + "' and is_deleted='0' and ghzt !='" + ghztType + "' and fk_psmc ='" + fk_psmc + "' ";
                        List<CCObject> manageGroup = this.cqlQuery("manage_group", findKeHu);
                        if (manageGroup.size() > 0) {
                            yg_lon = manageGroup.get(0).get("dlwzla") == null ? "" : manageGroup.get(0).get("dlwzla") + "";
                            yg_lat = manageGroup.get(0).get("dlwzco") == null ? "" : manageGroup.get(0).get("dlwzco") + "";
                        }
                        if (yg_lon.equals("") || yg_lat.equals("")) {
                            // if (true) trigger.addErrorMessage("当前管户小组的经纬度为空，请及时补充");

                        }
                        // 纬度
                        double lat1 = Math.toRadians(Double.parseDouble("".equals(lat) ? "0.00" : lat));
                        double lat2 = Math.toRadians(Double.parseDouble("".equals(yg_lat) ? "0.00" : yg_lat));
                        // 经度
                        double lng1 = Math.toRadians(Double.parseDouble("".equals(lon) ? "0.00" : lon));
                        double lng2 = Math.toRadians(Double.parseDouble("".equals(yg_lon) ? "0.00" : yg_lon));
                        // 纬度之差
                        double a = lat1 - lat2;
                        // 经度之差
                        double b = lng1 - lng2;
                        // 计算两点距离的公式
                        double distance = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a / 2), 2) +
                                Math.cos(lat1) * Math.cos(lat2) * Math.pow(Math.sin(b / 2), 2)));
                        // 弧长乘地球半径, 返回单位: 米
                        distance = distance * EARTH_RADIUS;
                        if (num==0) {
                            if (distance > 500) {
                                String findName = "select name from psmc where id ='"+fk_psmc+"' ";
                                List<CCObject> psmc = this.cqlQuery("psmc", findName);
                                String ppName = "";
                                if (psmc.size()>0){
                                    ppName = psmc.get(0).get("name")==null?"":psmc.get(0).get("name")+"";
                                }
                                // if (true) trigger.addErrorMessage("当前位置与，您在"+ppName+"中的客户位置之前距离大于200米");

                                CCObject notice = new CCObject("notice");
                                notice.put("accountId", userInfoUserId);
                                notice.put("record_id", khmc);
                                notice.put("noticeInfo", "当前"+now+"，你创建的活动所在的位置，与您在"+ppName+"中的客户位置之前距离大于200米");
                                this.insert(notice);
                            } else {
                                String updateEleoppJIEduan = "update eleopp set jieduan ='" + eleoppJieduanType2 + "',recordtype='" + eleoppTYPE + "',es_time='" + now + "',timeEndOne='" + now + "',timeTwoStart='" + now + "' where id ='" + id + "' ";
                                this.cqlQuery("eleopp", updateEleoppJIEduan);
                                //阶段2，升迁三阶段，所有字段填写完毕；更新管护小组状态为第三阶段
                                if (
                                        org.apache.commons.lang3.StringUtils.isNotBlank(one_year_num) &&
                                                org.apache.commons.lang3.StringUtils.isNotBlank(habbit) &&
                                                org.apache.commons.lang3.StringUtils.isNotBlank(strategy) &&
                                                org.apache.commons.lang3.StringUtils.isNotBlank(pay_method) &&
                                                org.apache.commons.lang3.StringUtils.isNotBlank(decision) &&
                                                org.apache.commons.lang3.StringUtils.isNotBlank(tender)) {

                                    String manager_sql = "update manage_group set ghzt='" + start_status + "',get_time='" + now + "'" +
                                            "where fk_account='" + khmc + "' " +
                                            "and is_deleted='0' " +
                                            "and fk_ccuser='" + ownerid + "'";
                                    String eleopp3_sql = "update eleopp set jieduan='" + jieduan3 + "',timeTwoEnd='" + now + "',timeThreeStart='" + now + "' " +
                                            "where id='" + id + "'";

                                    //更新三阶段
                                    this.cqlQuery("eleopp", eleopp3_sql);
                                    //更新管护小组状态
                                    this.cqlQuery("manage_group", manager_sql);

                                }

                            }
                        }else {
                            String updateEleoppJIEduan = "update eleopp set jieduan ='" + eleoppJieduanType2 + "',recordtype='" + eleoppTYPE + "',es_time='" + now + "',timeEndOne='" + now + "',timeTwoStart='" + now + "' where id ='" + id + "' ";
                            this.cqlQuery("eleopp", updateEleoppJIEduan);
                            //阶段2，升迁三阶段，所有字段填写完毕；更新管护小组状态为第三阶段
                            if (
                                    org.apache.commons.lang3.StringUtils.isNotBlank(one_year_num) &&
                                            org.apache.commons.lang3.StringUtils.isNotBlank(habbit) &&
                                            org.apache.commons.lang3.StringUtils.isNotBlank(strategy) &&
                                            org.apache.commons.lang3.StringUtils.isNotBlank(pay_method) &&
                                            org.apache.commons.lang3.StringUtils.isNotBlank(decision) &&
                                            org.apache.commons.lang3.StringUtils.isNotBlank(tender)) {

                                String manager_sql = "update manage_group set ghzt='" + start_status + "',get_time='" + now + "'" +
                                        "where fk_account='" + khmc + "' " +
                                        "and is_deleted='0' " +
                                        "and fk_ccuser='" + ownerid + "'";
                                String eleopp3_sql = "update eleopp set jieduan='" + jieduan3 + "',timeTwoEnd='" + now + "',timeThreeStart='" + now + "' " +
                                        "where id='" + id + "'";

                                //更新三阶段
                                this.cqlQuery("eleopp", eleopp3_sql);
                                //更新管护小组状态
                                this.cqlQuery("manage_group", manager_sql);

                            }

                        }
                    }
                }
                /*低频*/
                else if ((jieduan.equals(eleoppJieduanType)) && (frequece.equals(frequeceType))) {
                    String updateEleoppJIEduan = "update eleopp set jieduan ='" + eleoppJieduanType2 + "',recordtype='" + eleoppTYPE + "',es_time='" + now + "',timeEndOne='" + now + "',timeTwoStart='" + now + "' where id ='" + id + "' ";
                    this.cqlQuery("eleopp", updateEleoppJIEduan);
                    //阶段2，升迁三阶段，所有字段填写完毕；更新管护小组状态为第三阶段
                    if (
                            org.apache.commons.lang3.StringUtils.isNotBlank(one_year_num) &&
                                    org.apache.commons.lang3.StringUtils.isNotBlank(habbit) &&
                                    org.apache.commons.lang3.StringUtils.isNotBlank(strategy) &&
                                    org.apache.commons.lang3.StringUtils.isNotBlank(pay_method) &&
                                    org.apache.commons.lang3.StringUtils.isNotBlank(decision) &&
                                    org.apache.commons.lang3.StringUtils.isNotBlank(tender)) {

                        String manager_sql = "update manage_group set ghzt='" + start_status + "',get_time='" + now + "'" +
                                "where fk_account='" + khmc + "' " +
                                "and is_deleted='0' " +
                                "and fk_ccuser='" + ownerid + "'";
                        String eleopp3_sql = "update eleopp set jieduan='" + jieduan3 + "',timeTwoEnd='" + now + "',timeThreeStart='" + now + "' " +
                                "where id='" + id + "'";

                        //更新三阶段
                        this.cqlQuery("eleopp", eleopp3_sql);
                        //更新管护小组状态
                        this.cqlQuery("manage_group", manager_sql);

                    }
                }
            }
        }
    }

//    新建事件
    public void  afterInsert1(){

        String khmc = "";
        String relateid = record_new.get("relateid") == null ? "" : record_new.get("relateid") + "";// 相关项
        java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("yyyy-MM-dd");//转换格式
        String createdate = sdf.format(new Date());
        String position = record_new.get("position") == null ? "" : record_new.get("position") + "";// 位置
        String remark = record_new.get("remark") == null ? "" : record_new.get("remark") + "";//内容
        String whoid=record_new.get("whoid")==null?"":(String)record_new.get("whoid");//潜客
        String type = record_new.get("type") == null ? "" : record_new.get("type") + "";// 事件类型
        String tgzc = record_new.get("tgzc") == null ? "" : record_new.get("tgzc") + "";//
        SimpleDateFormat fmt = new SimpleDateFormat("yyyy-MM-dd");//设置日期格式
        String  nowdate=fmt.format(new Date());

        // 获取相关项的事件数量
        int eventnum = this.cquery("Event", "id='" + relateid + "'").size() + 1;
        // 获取相关项api
        String obj_suffix = "";
        if (!"".equals(relateid)) {
            obj_suffix = relateid.substring(0, 3);
        }
        String sql2 = "select SCHEMETABLE_NAME api from tp_sys_object where prefix='" + obj_suffix + "'";
        List<CCObject> list2 = this.cqlQuery("works", sql2);
        String api = "";
        String accounttype = "";// 客户记录类型
        String opptype = "";// 商机记录类型
        String fk_campaign_name = "";// 关联活动
        String fk_partner_name = "";// 关联渠道人
        String fk_company_name = "";// 关联渠道公司
        String core_bussiness = "";// 核心企业
        if (list2.size() > 0) {
            api = list2.get(0).get("api") == null ? "" : list2.get(0).get("api") + "";
        }
        if ("签到拜访".equals(type) || "记录电话".equals(type)||"微信沟通".equals(type)) {
            /* 如果相关项是渠道商机（营销人员） */
            if ("market_member".equals(api)) {
                List<CCObject> memlist = this.cquery("market_member", "id='" + relateid + "'");
                if(memlist.size()>0){
                    if ("记录电话".equals(type)||"微信沟通".equals(type)) {
                        String phone_num = memlist.get(0).get("phone_num") == null ? "0" : memlist.get(0).get("phone_num") + "";
                        int phonenum = Integer.parseInt(phone_num) + 1;
                        memlist.get(0).put("phone_num", phonenum);
                        //产业渠道人
                        String parid = memlist.get(0).get("market_member") == null ? "" : memlist.get(0).get("market_member") + "";
                        if (!"".equals(parid)) {
                            List<CCObject> parlist = this.cquery("partner", "id='" + parid + "'");
                            if(parlist.size()>0){
                                String phone_num2 = parlist.get(0).get("phone_num") == null ? "0" : parlist.get(0).get("phone_num") + "";
                                int phonenum2 = Integer.parseInt(phone_num2)+1;
                                parlist.get(0).put("phone_num", phonenum2);
                                this.update(parlist.get(0));
                            }

                        }
                        //活动
                        String f1 = memlist.get(0).get("fk_campaign_name") == null ? "" : memlist.get(0).get("fk_campaign_name") + "";
                        if (!"".equals(f1)) {
                            List<CCObject> camlist = this.cquery("campaign", "id='" + f1 + "'");
                            if(camlist.size()>0){
                                String dhl = camlist.get(0).get("dhl") == null ? "0" : camlist.get(0).get("dhl") + "";
                                int dhl_num = Integer.parseInt(dhl) + 1;
                                camlist.get(0).put("dhl", dhl_num);
                                this.update(camlist.get(0));
                                //父级营销活动
                                String f2 = camlist.get(0).get("fjschd") == null ? "" : camlist.get(0).get("fjschd") + "";
                                if (!"".equals(f2)) {
                                    List<CCObject> camlist1 = this.cquery("campaign", "id='" + f2 + "'");
                                    if(camlist1.size()>0){
                                        String dhl1 = camlist1.get(0).get("dhl") == null ? "0" : camlist1.get(0).get("dhl") + "";
                                        int dhl1_num = Integer.parseInt(dhl1)+1;
                                        camlist1.get(0).put("dhl", dhl1_num);
                                        this.update(camlist1.get(0));
                                    }
                                }
                            }
                        }

                    } else {

                        String visit_num = memlist.get(0).get("visit_num") == null ? "0" : memlist.get(0).get("visit_num") + "";
                        int visitnum = Integer.parseInt(visit_num) + 1;
                        memlist.get(0).put("visit_num", visitnum);
                        //产业渠道人
                        String parid = memlist.get(0).get("market_member") == null ? "" : memlist.get(0).get("market_member") + "";
                        if (!"".equals(parid)) {

                            List<CCObject> parlist = this.cquery("partner", "id='" + parid + "'");
                            if(parlist.size()>0){
                                String visit_num2 = parlist.get(0).get("visit_num") == null ? "0" : parlist.get(0).get("visit_num") + "";
                                int visitnum2 = Integer.parseInt(visit_num2)+1;
                                parlist.get(0).put("visit_num", visitnum2);
                                this.update(parlist.get(0));
                            }

                        }
                        //活动
                        String f1 = memlist.get(0).get("fk_campaign_name") == null ? "" : memlist.get(0).get("fk_campaign_name") + "";
                        if (!"".equals(f1)) {
                            List<CCObject> camlist = this.cquery("campaign", "id='" + f1 + "'");
                            if(camlist.size()>0){
                                String dhl = camlist.get(0).get("bfl") == null ? "0" : camlist.get(0).get("bfl") + "";
                                int dhl_num = Integer.parseInt(dhl) + 1;
                                camlist.get(0).put("bfl", dhl_num);
                                this.update(camlist.get(0));
                                //父级营销活动
                                String f2 = camlist.get(0).get("fjschd") == null ? "" : camlist.get(0).get("fjschd") + "";
                                if (!"".equals(f2)) {
                                    List<CCObject> camlist1 = this.cquery("campaign", "id='" + f2 + "'");
                                    if(camlist1.size()>0){
                                        String dhl1 = camlist1.get(0).get("bfl") == null ? "0" : camlist1.get(0).get("bfl") + "";
                                        int dhl1_num = Integer.parseInt(dhl1)+1;
                                        camlist1.get(0).put("bfl", dhl1_num);
                                        this.update(camlist1.get(0));
                                    }
                                }
                            }
                        }
                    }
                    this.update(memlist.get(0));
                }
            }
            /* 如果相关项是产业渠道人 */
            if ("partner".equals(api)) {
                List<CCObject> memlist=this.cquery("market_member","market_member='"+relateid+"' order by createdate desc");
                if(memlist.size()>0){
                    if ("记录电话".equals(type)||"微信沟通".equals(type)) {
                        String phone_num = memlist.get(0).get("phone_num") == null ? "0" : memlist.get(0).get("phone_num") + "";
                        int phonenum = Integer.parseInt(phone_num) + 1;
                        memlist.get(0).put("phone_num", phonenum);
                        //产业渠道人
                        String parid = memlist.get(0).get("market_member") == null ? "" : memlist.get(0).get("market_member") + "";
                        if (!"".equals(parid)) {
                            List<CCObject> parlist = this.cquery("partner", "id='" + parid + "'");
                            if(parlist.size()>0){
                                parlist.get(0).put("recently_followed",remark);//最近更近内容
                                parlist.get(0).put("last_date",nowdate);//最近联系日期
                                String phone_num2 = parlist.get(0).get("phone_num") == null ? "0" : parlist.get(0).get("phone_num") + "";
                                int phonenum2 = Integer.parseInt(phone_num2)+1;
                                parlist.get(0).put("phone_num", phonenum2);
                                this.update(parlist.get(0));
                                //活动
                                String f1 = memlist.get(0).get("fk_campaign_name") == null ? "" : memlist.get(0).get("fk_campaign_name") + "";
                                if (!"".equals(f1)) {
                                    List<CCObject> camlist = this.cquery("campaign", "id='" + f1 + "'");
                                    if(camlist.size()>0){
                                        String dhl = camlist.get(0).get("dhl") == null ? "0" : camlist.get(0).get("dhl") + "";
                                        int dhl_num = Integer.parseInt(dhl) + 1;
                                        camlist.get(0).put("dhl", dhl_num);
                                        this.update(camlist.get(0));
                                        //父级营销活动
                                        String f2 = camlist.get(0).get("fjschd") == null ? "" : camlist.get(0).get("fjschd") + "";
                                        if (!"".equals(f2)) {
                                            List<CCObject> camlist1 = this.cquery("campaign", "id='" + f2 + "'");
                                            if(camlist1.size()>0){
                                                String dhl1 = camlist1.get(0).get("dhl") == null ? "0" : camlist1.get(0).get("dhl") + "";
                                                int dhl1_num = Integer.parseInt(dhl1)+1;
                                                camlist1.get(0).put("dhl", dhl1_num);
                                                this.update(camlist1.get(0));
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    } else {

                        String visit_num = memlist.get(0).get("visit_num") == null ? "0" : memlist.get(0).get("visit_num") + "";
                        int visitnum = Integer.parseInt(visit_num) + 1;
                        memlist.get(0).put("visit_num", visitnum);
                        //产业渠道人
                        String parid = memlist.get(0).get("market_member") == null ? "" : memlist.get(0).get("market_member") + "";
                        if (!"".equals(parid)) {

                            List<CCObject> parlist = this.cquery("partner", "id='" + parid + "'");
                            if(parlist.size()>0){
                                parlist.get(0).put("recently_followed",remark);//最近更近内容
                                parlist.get(0).put("last_date",nowdate);//最近联系日期
                                String visit_num2 = parlist.get(0).get("visit_num") == null ? "0" : parlist.get(0).get("visit_num") + "";
                                int visitnum2 = Integer.parseInt(visit_num2)+1;
                                parlist.get(0).put("visit_num", visitnum2);
                                this.update(parlist.get(0));
                            }
                        }
                        //活动
                        String f1 = memlist.get(0).get("fk_campaign_name") == null ? "" : memlist.get(0).get("fk_campaign_name") + "";
                        if (!"".equals(f1)) {
                            List<CCObject> camlist = this.cquery("campaign", "id='" + f1 + "'");
                            if(camlist.size()>0){
                                String dhl = camlist.get(0).get("bfl") == null ? "0" : camlist.get(0).get("bfl") + "";
                                int dhl_num = Integer.parseInt(dhl) + 1;
                                camlist.get(0).put("bfl", dhl_num);
                                this.update(camlist.get(0));
                                //父级营销活动
                                String f2 = camlist.get(0).get("fjschd") == null ? "" : camlist.get(0).get("fjschd") + "";
                                if (!"".equals(f2)) {
                                    List<CCObject> camlist1 = this.cquery("campaign", "id='" + f2 + "'");
                                    if(camlist1.size()>0){
                                        String dhl1 = camlist1.get(0).get("bfl") == null ? "0" : camlist1.get(0).get("bfl") + "";
                                        int dhl1_num = Integer.parseInt(dhl1)+1;
                                        camlist1.get(0).put("bfl", dhl1_num);
                                        this.update(camlist1.get(0));
                                    }
                                }
                            }
                        }
                    }
                    this.update(memlist.get(0));
                }
            }
        }
        if("Account".equals(api)){
            List<CCObject> acclist=this.cquery("Account","id='"+relateid+"'");
            acclist.get(0).put("late_date",nowdate);
            acclist.get(0).put("recently_followed",remark);
            String lxcs=acclist.get(0).get("frequency")==null?"0":acclist.get(0).get("frequency")+"";
            int lxcs_num=Integer.parseInt(lxcs)+1;
            acclist.get(0).put("frequency",lxcs_num);
            this.update(acclist.get(0));
        }
        if("Opportunity".equals(api)){
            List<CCObject> opportunity_list=this.cquery("Opportunity","id='"+relateid+"'");
            if (opportunity_list.size()>0) {
                String opportunity_name = opportunity_list.get(0).get("name")==null?"0":opportunity_list.get(0).get("name")+"";
                opportunity_list.get(0).put("late_date", nowdate);
                opportunity_list.get(0).put("recently_followed", remark);
                String lxcs = opportunity_list.get(0).get("frequency") == null ? "0" : opportunity_list.get(0).get("frequency") + "";
                int lxcs_num = Integer.parseInt(lxcs) + 1;
                opportunity_list.get(0).put("frequency", lxcs_num);
                this.update(opportunity_list.get(0));
                if (!"".equals(tgzc)) {
                    SendEmail sendEmail = new SendEmail(userInfo);
                    String email = "songqc@cloudcc.com";//用户邮箱
                    String[] emails = new String[1];
                    emails[0] = email;
                    String subject = "请求支持邮件通知";
                    String content = "您好，<br/>" +
                            "<br/>" +
                            "<br/>" +
                            "<br/>" +
                            "<a href=\"https://k8mm3cmt3235c7ed72cede6e.cloudcc.com/query.action?id=" + relateid + "&m=query\" target=\"_blank\" >" + opportunity_name + "</a>需要总部提供支持，具体内容如下：<br/>" +
                            "<br/>" +
                            ""+tgzc+"";
                    sendEmail.sendMailFromSystem(emails, null, null, subject, content, false);

                }
            }
        }
        if(!"".equals(whoid)){
            List<CCObject> leadlist=this.cquery("Lead","id='"+whoid+"'");
            if(leadlist.size()>0){
                leadlist.get(0).put("late_date",nowdate);
                leadlist.get(0).put("recently_followed",remark);
                String lxcs=leadlist.get(0).get("frequency")==null?"0":leadlist.get(0).get("frequency")+"";
                int lxcs_num=Integer.parseInt(lxcs)+1;
                leadlist.get(0).put("frequency",lxcs_num);
                this.update(leadlist.get(0));
            }

        }
    }

}
